package org.tao.lightningmq.common.tcp;

import org.tao.lightningmq.common.constants.BrokerConstants;
import org.tao.lightningmq.common.enums.NameServerResponseCode;

/**
 * @Author lht
 * @date 2025/1/7 - 15:03
 * @description: tcp消息
 */
public class TcpMsg {

    private short magic;
    private int code;
    private int len;
    private byte[] body;
    /**
     * 2 + 4 + 4
     * Decode时需要用到
     */
    public static final int BASE_LEN = 10;

    public TcpMsg(int code, byte[] body) {
        this.code = code;
        this.body = body;
        this.len = body.length;
        this.magic = BrokerConstants.DEFAULT_MAGIC_NUM;
    }

    public TcpMsg(NameServerResponseCode code, byte[] body) {
        this(code.getCode(), body);
    }

    public TcpMsg(NameServerResponseCode code) {
        this(code.getCode(), code.getDesc().getBytes());
    }

    public short getMagic() {
        return magic;
    }

    public void setMagic(short magic) {
        this.magic = magic;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getLen() {
        return len;
    }

    public void setLen(int len) {
        this.len = len;
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

}
